package com.suyx.job.job;

import static org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace;

import java.util.List;

import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.alibaba.fastjson.JSON;
import com.suyx.job.entity.JobInfo;
import com.suyx.job.entity.Result;
import com.suyx.job.entity.RoleInfo;

import lombok.extern.slf4j.Slf4j;

/**
 * @Auther: lanyanhua
 * @Date: 2018/10/17 0017 14:45
 * @Description:
 */
@Slf4j
public class MhxyDelRedisForRoleNameExecuteJob extends ExecuteJob {
	@Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("进入了--- MhxyDelRedisForRoleNameExecuteJob: ");
        JobDataMap param = jobExecutionContext.getMergedJobDataMap();
        jobInfo = (JobInfo) param.get("jobInfo");
        String subject = "项目：" + jobInfo.getJobGroup() + ",执行任务：" + jobInfo.getJobName();
        log.info("id:" + jobInfo.getJobId() + "," + subject);
        Result result = executeCall();
        log.info(jobInfo.getJobGroup() + "MhxyDelRedisForRoleNameExecuteJob执行完成~");
    }
	
	@Override
    public Result executeCall() {
		try {
            Result result = restTemplate.getForObject(jobInfo.getExecuteAddress(), Result.class);
            if (result != null && result.isSuccess()) {
                log.info("执行成功：result" + JSON.toJSONString(result));
                return new Result(true,"200","执行成功！！");
            } else {
                log.error("执行失败：result:" + JSON.toJSONString(result));
                return new Result(false,"500","执行失败，请尽快处理！！！");
            }
        } catch (Exception e) {
            log.error( "执行时出现异常：" + getStackTrace(e));
            return new Result(false, "500", "执行时出现异常");
        }
    }

   
}
